import moment from "moment"
import { sample } from "lodash";

let weatherList = [
    {
        id: 1,
        name: "晴天",
        desc: "阳光灿烂，除了热什么都好",
        info: '阳光生产效率增加20%',
        day: 100,
        night: 0,
        sunDropAmountBuff: 1.2,
        sunDropRateBuff: 1,
    },
    {
        id: 2,
        name: "阴天",
        desc: "暗流涌动...",
        info: '僵尸刷新概率增加30%',
        day: 10,
        night: 100,
        sunDropAmountBuff: 1,
        sunDropRateBuff: 1,
    },
    {
        id: 3,
        name: "小雨",
        desc: "雨天路滑，小心脚下", 
        info: '阳光生产效率减少10%, 阳光掉落频率增加20%',
        day: 5,
        night: 10,
        sunDropAmountBuff: 0.9,
        sunDropRateBuff: 1.2,
    },
    {
        id: 4,
        name: "中雨",
        desc: "雨逐渐变大了...",
        info: '阳光生产效率减少20%, 阳光掉落频率增加30%',
        day: 5,
        night: 10,
        sunDropAmountBuff: 0.8,
        sunDropRateBuff: 1.3,
    },
    {
        id: 5,
        name: "大雨",
        desc: "雨下得很大...",
        info: '阳光生产效率减少50%, 阳光掉落频率增加50%',
        day: 5,
        night: 10,
        sunDropAmountBuff: 0.5,
        sunDropRateBuff: 1.5,
    },
    {
        id: 6,
        name: "大雾",
        desc: "雾霾天，能见度大幅下降了",
        info: '僵尸刷新概率增加50%, 僵尸攻击力减少50%',
        day: 2,
        night: 10,
        sunDropAmountBuff: 1,
        sunDropRateBuff: 1,
    },
    {
        id: 7,
        name: "雷暴",
        desc: "雷电交加，请呆在室内",
        info: '阳光生产效率减少80%, 阳光掉落频率增加80%',
        day: 2,
        night: 10,
        sunDropAmountBuff: 0.2,
        sunDropRateBuff: 1.8,
    },
    {
        id: 8,
        name: "冰雹",
        desc: "极端天气，请勿出门",
        info: '僵尸攻击力增加50%, 植物攻击力增加50%',
        day: 1,
        night: 2,
        sunDropAmountBuff: 1,
        sunDropRateBuff: 1,
    },
    {
        id: 9,
        name: "台风",
        desc: "极端天气，请勿出门",
        info: '阳光生产效率减少90%, 僵尸攻击力减少90%',
        day: 1,
        night: 1,
        sunDropAmountBuff: 0.1,
        sunDropRateBuff: 1,
    },
]

const getWeatherList = () => {
    return [
        {
            id: 1,
            name: "晴天",
            desc: "阳光灿烂，除了热什么都好",
            info: '阳光生产效率增加20%',
            day: 100,
            night: 0,
            sunDropAmountBuff: 1.2,
            sunDropRateBuff: 1,
        },
        {
            id: 2,
            name: "阴天",
            desc: "暗流涌动...",
            info: '僵尸刷新概率增加30%',
            day: 10,
            night: 100,
            sunDropAmountBuff: 1,
            sunDropRateBuff: 1,
        },
        {
            id: 3,
            name: "小雨",
            desc: "雨天路滑，小心脚下", 
            info: '阳光生产效率减少10%, 阳光掉落频率增加20%',
            day: 5,
            night: 10,
            sunDropAmountBuff: 0.9,
            sunDropRateBuff: 1.2,
        },
        {
            id: 4,
            name: "中雨",
            desc: "雨逐渐变大了...",
            info: '阳光生产效率减少20%, 阳光掉落频率增加30%',
            day: 5,
            night: 10,
            sunDropAmountBuff: 0.8,
            sunDropRateBuff: 1.3,
        },
        {
            id: 5,
            name: "大雨",
            desc: "雨下得很大...",
            info: '阳光生产效率减少50%, 阳光掉落频率增加50%',
            day: 5,
            night: 10,
            sunDropAmountBuff: 0.5,
            sunDropRateBuff: 1.5,
        },
        {
            id: 6,
            name: "大雾",
            desc: "雾霾天，能见度大幅下降了",
            info: '僵尸刷新概率增加50%, 僵尸攻击力减少50%',
            day: 2,
            night: 10,
            sunDropAmountBuff: 1,
            sunDropRateBuff: 1,
        },
        {
            id: 7,
            name: "雷暴",
            desc: "雷电交加，请呆在室内",
            info: '阳光生产效率减少80%, 阳光掉落频率增加80%',
            day: 2,
            night: 10,
            sunDropAmountBuff: 0.2,
            sunDropRateBuff: 1.8,
        },
        {
            id: 8,
            name: "冰雹",
            desc: "极端天气，请勿出门",
            info: '僵尸攻击力增加50%, 植物攻击力增加50%',
            day: 1,
            night: 2,
            sunDropAmountBuff: 1,
            sunDropRateBuff: 1,
        },
        {
            id: 9,
            name: "台风",
            desc: "极端天气，请勿出门",
            info: '阳光生产效率减少90%, 僵尸攻击力减少90%',
            day: 1,
            night: 1,
            sunDropAmountBuff: 0.1,
            sunDropRateBuff: 1,
        },
    ]
}

const getTargetWeather = (selectWeatherId = false) => {
    if (selectWeatherId) {
        let weather = getWeatherList().find(weather => weather.id === selectWeatherId)
        return weather
    }
    else {
        let isDay = moment().hour() >= 6 && moment().hour() < 18
        let arr = []
        getWeatherList().forEach(weather => {
            if (isDay) {
                for (let index = 0; index < weather.day; index++) {
                    arr.push(weather)
                }
            }
            else {
                for (let index = 0; index < weather.night; index++) {
                    arr.push(weather)
                }
            }
        })
        return sample(arr)
    }
}
export {
    weatherList,
    getWeatherList,
    getTargetWeather,
}